//
//  ViewController.m
//  10_CustomTableViewCell
//
//  Created by GivenBmli on 16/7/27.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "ViewController.h"
#import "CustomTableViewCell.h"
#import "LXCustomTableViewCell.h"
#import "NewsObject.h"
#define kReturn @"return"
#define kCustermReuse @"customReuse"
@interface ViewController ()<UITableViewDelegate , UITableViewDataSource>
@property (nonatomic , strong)UITableView *tableView;
@property (nonatomic , strong)NSMutableArray *array;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//     数据的传递依赖Model 传对象存对象取对象
    NewsObject *newSObject = [[NewsObject alloc]initWithNewsImage:@"2" newsTitle:@"上海高温当街十分钟烤熟培根" newsDescripition:@"无🔥烤培根" newsNumberCount:@"155万点击量"];
    self.array = [NSMutableArray arrayWithObject:newSObject];
    
    
//    NSArray *arr = @[@"唐益梦", @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"李毅然", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪"];
//    self.array = [NSMutableArray arrayWithArray:arr];
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerClass:[LXCustomTableViewCell class] forCellReuseIdentifier:kReturn];
    
    [self.view addSubview:_tableView];
//    使用自定义Cell需要修改
//    1.注册的应cell的类型
//    2.重用池取出celld的类型
//    3.自定义cell继承与UITableViewCell
//     多种Cell混合使用
//    注册Cell 时 注意宠用标示不要相同
    [_tableView registerClass:[CustomTableViewCell class] forCellReuseIdentifier:kCustermReuse];

    
    self.navigationItem.rightBarButtonItem = self.editButtonItem;

}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [_tableView setEditing:editing animated:animated];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 104;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _array.count;
}
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    LXCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kReturn];
//    cell.textLabel.text = _array[indexPath.row];
////    给自定义视图赋值
////    cell.nemsImageView.image = [UIImage imageNamed:@"2"];
////    cell.titileLabel.text = @"上海高温当街十分钟烤熟培根";
////    cell.descriptopnlabel.text = @"今日,上海地表温度达到50度,无🔥考培根";
////    cell.numberCountsLaberl.text = @"155万点击量";
////    cell.newsObjiect = _array[indexPath.row];
//    
//    return cell;
//}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    多种Cell同时使用,可以根据下标决定样式
//    判断完整
    if (indexPath.row == 1) {
        CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kReturn];
        return cell;
    }else {
        LXCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCustermReuse];
        cell.newsObjiect = _array[indexPath.row];
        return cell;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
